#coding=utf-8

'''
@author: cnweike@gmail.com
@summary: 本模块主要定义维度类，也可以叫做观测角度
'''

import attr_settings

class Dimension(object):
    '''
        维度的名称：name
        维度的标签名称：label
        维度的描述：desc
        维度来自于哪个库：dbname
        维度来自于哪个表：tbname
        维度来自于哪个字段：colname
        维度相关的概念：concepts
    '''
    def __init__(self, **kwargs):
        '''初始化维度的映射关系'''
        self.name = kwargs.get('name', None) # 比如“用户付费时间”
        self.label = kwargs.get('label', None) # 比如 “用户付费时间”
        self.desc = kwargs.get('desc', None) # 比如“用户的付费时间”
        self.dbname = kwargs.get('dbname', None) # 比如“default”
        self.tbname = kwargs.get('tbname', None) # 比如“subkbrecords”
        self.colname = kwargs.get('colname', None) # 比如“sub_time”
        self.concepts = kwargs.get('concepts', None) # 比如[{'name':'年', 'type':'sql', 'define':'year(%(colname)s)'},{'name':'月', 'type':'sql', 'define':'month(%(colname)s)'}]
        
    def _all_concepts(self):
        return [item for item in self.concepts]
    
    

if __name__ == '__main__':
    kwargs = attr_settings.settingsindb['mixi_farm_subkb'][0]
    dim = Dimension(**kwargs)
    for item in dim._all_concepts():
        print item
    